#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class HugeInteger
{
    public:
        string content;
        HugeInteger();
        HugeInteger(int a);
        HugeInteger(string a);
};
HugeInteger::HugeInteger()
{
    content = "0";
}
HugeInteger::HugeInteger(int a)
{
    stringstream ss;
    ss << a;
    ss >> content;
}

HugeInteger::HugeInteger(string a)
{
    content = a;
}
HugeInteger operator+(HugeInteger h1, HugeInteger h2)
{
    int slen = 0;
    //准备 c = a + b
    string a,b,c;
    //两个数对齐
    if(h1.content.length() > h2.content.length())
    {
        slen = h1.content.length();
        a = h1.content;
        string zeroString(slen-h2.content.length(),'0');
        b = zeroString + h2.content;   
    }
    else
    {
        slen = h2.content.length();
        b = h2.content;
        string zeroString(slen-h1.content.length(),'0');
        a = zeroString + h1.content;   

    }
    int carry = 0;
    for(int i = slen -1; i >= 0; i--)
    {
        int sum = a[i]-'0' + b[i] -'0' + carry;
        string s(1,(char)((sum%10) + '0'));
        c =  s + c; 
        carry = sum / 10;
    }
    if(carry > 0)
        c = "1" + c;
    return c;
}
HugeInteger operator+(HugeInteger h,int a)
{
    HugeInteger aa(a);
    HugeInteger b = h + aa;
    return b;
}
HugeInteger operator+( HugeInteger h, string a)
{
    HugeInteger aa(a);
    HugeInteger b = h + aa;
    return b;
}
ostream & operator << (ostream & os,const HugeInteger  a)
{
    os<<a.content; 
    return os;
}
int main()
{

   HugeInteger n1( 7654321 );
   HugeInteger n2( 7891234 );
   HugeInteger n3( "99999999999999999999999999999" );
   HugeInteger n4( "1" );
   HugeInteger n5;
   cout << "n1 is " << n1 << "\nn2 is " << n2
      << "\nn3 is " << n3 << "\nn4 is " << n4
      << "\nn5 is " << n5 << "\n\n";
   n5 = n1 + n2;
   cout << n1 << " + " << n2 << " = " << n5 << "\n\n";

   cout << n3 << " + " << n4 << "\n= " << ( n3 + n4 ) << "\n\n";

   n5 = n1 + 9;
   cout << n1 << " + " << 9 << " = " << n5 << "\n\n";
   n5 = n2 + "10000";
   cout << n2 << " + " << "10000" << " = " << n5 << endl;
    return 0;
}